var isOpened=0;//记录是否打开过
var modify_tab;
		//添加自定义宾栏
		var advancedColumnWindow_ = new Ext.Window({	
			width:670,	
	    	height: 500,
	    	layout: "border",
	    	title:'添加自定义列',
	    	modal: true,
	    	border:false,
	    	id: "customH_win_",
	    	closeAction: 'hide',
		    items: [
		          {
						height:608,
						width:all_width * 20 / 100,
						autoScroll: true,
						collapsible: true,
						id: 'tree-panel-measures',
						region: 'west',
						title: '所有字段',
						//enableDrag:true,
						ddGroup: 'customDDGroup',
						split: true,
						xtype: 'treepanel',
						margins: '2 2 2 2',
						useArrows:true,
						rootVisible : false,
						root: new Ext.tree.TreeNode({id:"-1",text:"目录",editable:false}),
						loader: new Ext.tree.TreeLoader({ 
			        		dataUrl: getRootPath()+'/customDetailTableColumn.report?key=dicTableDictionAdapter',
			        		listeners:{beforeload:function(treeLoader, node) {
					      	this.baseParams.id = node.id;
					      	this.baseParams.table = node.attributes.table;
					      	this.baseParams.DATASOURCE_NAME_ = '${datasource}';
					      	this.baseParams.table_code_ = node.attributes.table_code_;
					    }}
	        }),
						listeners:{
							beforeappend:function(tree,parent,node){
			         		//判断是否是报告期
								if(node.attributes.isTime=='true'){
									return false;	
								}else{
									return true;
								}
			         	}
						}
					}
		        ,{
		        	region:'center',
		        	width:320,
		        	height: 500,
		        	margins: '2 2 0 2',
		        	items:
		        		{
		        		title:'请输入表达式',
		        		layout: 'table',
		        		border:false,
		        		bodyStyle:'padding:10px 10px 10px 20px',
		        		layoutConfig: {columns:5},
		        		defaults:{frame:false,style:'padding:2px',minWidth: '60',style:{marginBottom: '10px'}},
		        		items:[
        		         {
        		    	    id:'selColumnName_',
        		    	    xtype:'textfield',
        		    	    width  : 350,
        		    	    colspan:5,
        		    	    emptyText:'请输入自定义列名称',
        		    	    allowBlank:false,
        		    	    blankText:'自定义列名称不能为空'
        		         },
		        		 {
				            xtype: "textarea",
				            id: "selColumnSql_",
				            width  : 350,
				            height : 140,
				            enableKeyEvents: true,
				            hideLabel:true,
				            allowBlank:false,
				            blankText:'自定义列表达式不能为空',
				            colspan:5,
				            style: {
		        			 	marginBottom: '10px',
				                imeMode:'disabled'		//屏蔽输入法
				            },
				            listeners:
			            	{
			            		'render':function(e)
			            		{
			            			//屏蔽粘贴和鼠标右键
			            			//Ext.get('selColumnSql_').dom.oncontextmenu = function(e){return false;};
			            			//Ext.get('selColumnSql_').dom.onpaste = function(e){return false;};
			            		}
			            		,'keypress':function(e)
			            		{//屏蔽键盘按键
									//event.keyCode = 0;
									//event.returnvalue = false;
			            		}
			            		
			            	}
				        }
 		        		,{
				        	xtype: "button",
		                    text: "select",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text=node.attributes.table+"."+node.attributes.code;
	                    			addquery(this,'selColumnSql_');
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
				        , {
				        	xtype: "button",
		                    text: "7",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
				        }
				        , {
				        	xtype: "button",
		                    text: "8",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "9",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " + ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
					        	xtype: "button",
			                    text: "trim",
			                    handler: function(){
		                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
		                    		if(node != null){
		                    			this.text="trim";
		                    			addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.code);
		                    		}else{
		                    			alert("请选择指标!");
		                    		}
			                    }
			            }
		                , {
				        	xtype: "button",
		                    text: "4",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
				        }
		                ,{
				        	xtype: "button",
		                    text: "5",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "6",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " - ",
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
				        	xtype: "button",
		                    text: "abs",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text="abs";
	                    			addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.code);
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
		                ,{
				        	xtype: "button",
		                    text: "1",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "2",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "3",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " * ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
				        	xtype: "button",
		                    text: "substr",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text="substr";
	                    			addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.code+",start,count");
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
		                ,{
				        	xtype: "button",
		                    text: "0",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: ".",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " % ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " / ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
				        	xtype: "button",
		                    text: "round",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text="round";
	                    			addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.code+",2");
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
		                ,{
				        	xtype: "button",
		                    text: " ( ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " ) ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "\'",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " || ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "replace",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text="replace";
	                    			addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.code+",'',''");
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		                }
		                ,{
				        	xtype: "button",
		                    text: " 清除 ",
		                    handler: function(){
		                    		Ext.getCmp('selColumnSql_').setValue() == "";
										}
		                }
		                ,{
				        	xtype: "button",
		                    text: " 保存 ",
		                    handler: function(){
			                	 if(!Ext.getCmp('selColumnName_').validate())
			                	 {
			                		return;
			                	 }
			                	 if(!Ext.getCmp('selColumnSql_').validate())
								 {
									return;
								 }
								 Ext.getCmp('customH_win_').hide();
								 Ext.getCmp('tree2').root.appendChild(new Ext.tree.TreeNode({leaf:true,text:Ext.getCmp('selColumnName_').getValue(),code:Ext.getCmp('selColumnSql_').getValue(),isCustom:'true',table:'custom',table_code_:'custom'}));
		                    }
		                }
		                ,{
				        	xtype: "button",
		                    text: " 保存并继续添加 ",
		                    colspan:2,
		                    minWidth:130,
		                    handler: function(){
			                	 if(!Ext.getCmp('selColumnName_').validate())
			                	 {
			                		return;
			                	 }
			                	 if(!Ext.getCmp('selColumnSql_').validate())
								 {
									return;
								 }
			                	 Ext.getCmp('tree2').root.appendChild(new Ext.tree.TreeNode({leaf:true,text:Ext.getCmp('selColumnName_').getValue(),code:Ext.getCmp('selColumnSql_').getValue(),isCustom:'true',table:'custom',table_code_:'custom'}));
		                    }
		                }
		        		]
		        	}
		        }
		   		]
		 	});//Ext.Window
		
	function addquery(o,sqlTextareaId,column)
	{
	    var tc = Ext.getDom(sqlTextareaId);
	    var tclen = tc.value.length;
	    tc.focus();
	    var str=o.text;
	    if(column)
	    	str+="("+column+")";
	    if(typeof document.selection != "undefined")
	    {
	        document.selection.createRange().text = str;  
	    }
	    else
	    {
	        tc.setValue(tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen));
	    }
	}